#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>


int main()
{
    pid_t id = fork();
    if(id==0)
    {   
        //子进程
         int cnt = 5;
         while(cnt)
         {
             printf("我是子进程,cnt: %d,pid: %d, ppid: %d\n", cnt--, getpid(), getppid());
             sleep(1);
         }
        exit(111);
    }
     // 父进程
    int status =0 ;
    pid_t ret_id = waitpid(id, &status, 0);
      printf("我是父进程，等待子进程成功, pid: %d, ppid: %d, ret_id: %d,child exit code: %d, child exit signal: %d\n",getpid(), getppid(), ret_id,(status>>8)&0xFF,status&0x7F);
    sleep(2);

    return 0;
}